# face detector 6
# cvlib

import cvlib
from matplotlib import pyplot as plt
import cv2


# visualize functions
def show_img_with_matplotlib(color_img, title, pos):
    img_rgb = color_img[:, :, ::-1]
    plt.subplot(1, 1, pos)
    plt.imshow(img_rgb)
    plt.title(title, fontsize=8)
    plt.axis('off')


# load image
img = cv2.imread("picture/006.jpg")
rgb_img = img[:, :, ::-1]
faces, confidences = cvlib.detect_face(rgb_img)


# draw face detector box
def show_detector(image, faces):
    for (startX, startY, endX, endY) in faces:
        cv2.rectangle(image, (startX, startY), (endX, endY), (255, 0, 0), 5)
    return image


# visualize
img_result = show_detector(img.copy(), faces)
show_img_with_matplotlib(img_result, "cvlib face detector:" + str(len(faces)), 1)

plt.show()
